<?php
require("../models/webconfig.php");
require("../models/class.connection.php");
require("../models/entities/class.OrderEntity.php");
require("../models/repositories/class.OrderRepository.php");
require("../models/entities/class.OrderDetailEntity.php");
require("../models/entities/class.ProductEntity.php");
require("../models/repositories/class.ProductRepository.php");
$order = "";
$listOrderdetails = array();
$orderRepository = new OrderRepository();
$productRepository = new ProductRepository();
if (isset($_POST['id'])) {
    $order = $orderRepository->GetOrder($_POST['id']);
    $listOrderdetails = $orderRepository->GetOrderDetails($order->ID_i);
}
$sum = 0;
?>
<html>

    <head>
        <style type="text/css">

            body h3{
                color:#d1681b;
                font-size: 17px;
                font-family: sans-serif;
            }

            body table{
                line-height: 20px;text-align: center;
            }

            .style1a{
                text-align: left;
            }
            .style1b{
                text-align: right;
            }

            .title{
                font-weight:bold;
            }

            #style2{
                border-top: 1px #676662 solid;
                border-left: 1px #676662 solid;
            }

            .border{
                border-bottom: 1px #676662 solid;
                border-right: 1px #676662 solid;
            }

        </style>
    </head>

    <body>
        <center>
            <h3>Chi tiết đơn đặt hàng</h3>
            <table width="70%">
                <?php if ($order != NULL) {
                ?>
                    <tr>
                        <td width="40%" class="style1b">Tên khách hàng</td>
                        <td class="style1a"><label><?php echo($order->CustomerName_s); ?></label></td>
                    </tr>
                    <tr>
                        <td class="style1b">Email</td>
                        <td class="style1a"><label><?php echo($order->Email_s); ?></label></td>
                    </tr>
                    <tr>
                        <td class="style1b">Địa chỉ</td>
                        <td class="style1a"><label><?php echo($order->Address_s); ?></label></td>
                    </tr>
                    <tr>
                        <td class="style1b">Số điện thoại</td>
                        <td class="style1a"><label><?php echo($order->Phone_s); ?></label></td>
                    </tr>
                    <tr>
                        <td class="style1b">Thời gian đặt hàng</td>
                        <td class="style1a"><label><?php echo(date("d/m/Y", strtotime($order->OrderTime_dt))); ?></label></td>
                    </tr>
                    <tr>
                        <td class="style1b">Thời gian giao hàng</td>
                        <td class="style1a"><label><?php echo(date("d/m/Y", strtotime($order->DeliveryTime_dt))); ?></label></td>
                    </tr>
                    <tr>
                        <td class="style1b">Trạng thái</td>
                        <td class="style1a"> <?php if ($order->Checked_b != "0") { ?>
                                <input type="checkbox" checked="checked">
                        <?php } else {
                        ?><input type="checkbox"><?php } ?></td>
                </tr>
                <?php } ?>
            </table>
            <h3>Danh sách sản phẩm</h3>
            <table id="style2" width="90%" cellspacing="0">
                <tr>
                    <td class="title border">STT</td>
                    <td class="title border">Mã đặt hàng</td>
                    <td class="title border">Tên sản phẩm</td>
                    <td class="title border">Đơn giá</td>
                    <td class="title border">Số lượng</td>
                    <td class="title border">Thành tiền</td>
                </tr>
                <?php if (count($listOrderdetails) > 0) {
                ?>
                <?php for ($i = 0; $i < count($listOrderdetails); $i++) {
                ?>
                        <tr>
                            <td class="border"><?php echo($i + 1); ?></td>
                            <td class="border"><?php echo($listOrderdetails[$i]->OrderID_i); ?></td>
                    <?php $product = $productRepository->GetDetail($listOrderdetails[$i]->ProductCode_s); ?>
                        <td class="border"><?php echo($product->Name_s); ?></td>
                        <td class="border"><?php echo(number_format($product->Price_f) . " VND"); ?></td>
                        <td class="border"><?php echo($listOrderdetails[$i]->Quantity_i); ?></td>
                        <td class="border"><?php echo(number_format($listOrderdetails[$i]->Quantity_i * $product->Price_f, 0) . " VND"); ?></td>
                    <?php $sum+=$listOrderdetails[$i]->Quantity_i * $product->Price_f; ?>
                    </tr>
                <?php } ?>
                <?php } ?>
            </table>
            <p><span style="font-weight: bold;">Tổng thành tiền </span> <?php echo(number_format($sum, 0) . " VND"); ?></p>
        </center>
    </body>

</html>
